package com.doctcloud.hisinfo.histable.domain.inpbill;

import com.baomidou.mybatisplus.annotation.TableName;
import com.doctcloud.common.core.annotation.Excel;
import com.doctcloud.common.core.annotation.NotZero;
import com.doctcloud.common.core.annotation.TableDesc;
import com.doctcloud.common.core.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.io.Serializable;
import java.util.Date;

import static com.doctcloud.common.core.utils.StringUtils.trim;

/**
 * @ClassName 住院费用记录
 * @Author samula
 * @Descripe product by com.doctcloud
 * @Data 2025-09-23 1:21
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = {"patientId", "visitId", "itemNo"})
@ToString
@TableDesc("住院收费清单")
public class InpBillDetailDo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Excel(name = "患者ID")
    @NotBlank(message = "患者ID不能为空")
    private String patientId;

    @Excel(name = "住院标识号",cellType = Excel.ColumnType.NUMERIC)
    @NotNull(message = "患者住院标识不能为空")
    @Positive(message = "患者住院标识必须大于0")
    private Integer visitId;

    @Excel(name = "收费序号")
    @NotZero(message = "收费序号不能为null或0")
    private Integer itemNo;

    @Excel(name = "计费类别代码")
    @NotBlank(message = "计费类别代码不能为空")
    private String itemClass;

    @Excel(name = "计费名称")
    @NotBlank(message = "计费名称不能为空")
    private String itemName;

    @Excel(name = "计费代码")
    @NotBlank(message = "计费代码不能为空")
    private String itemCode;

    @Excel(name = "项目规格")
    @NotBlank(message = "项目规格不能为空") // 修正：提示信息与字段名保持一致
    private String itemSpec;

    @Excel(name = "数量",cellType = Excel.ColumnType.NUMERIC)
    @NotZero(message = "数量不能为null或0")
    private Integer amount;

    @Excel(name = "单位")
    @NotBlank(message = "单位不能为空")
    private String units;

    @Excel(name = "开单科室代码")
    @NotBlank(message = "开单科室代码不能为空")
    private String orderedBy;

    @Excel(name = "执行科室代码")
    @NotBlank(message = "执行科室代码不能为空")
    private String performedBy;

    @Excel(name = "应收金额",cellType = Excel.ColumnType.NUMERIC)
    @NotZero(message = "应收金额不能为null或0")
    private Double costs;

    @Excel(name = "计价金额",cellType = Excel.ColumnType.NUMERIC)
    @NotZero(message = "计价金额不能为null或0")
    private Double charges;

    @Excel(name="计价时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date billingDateTime;

    @Excel(name = "操作员工号")
    private String operatorNo;

    @Excel(name = "收费单号")
    private String rcptNo;

    @Data
    public class primaryKey {
        private String patientId;
        private Integer visitId;
        private Integer itemNo;

        // 构造函数、Getters 和 Setters
        public primaryKey(String patientId, Integer visitId, Integer itemNo) {
            this.patientId = patientId;
            this.visitId = visitId;
            this.itemNo = itemNo;
        }
    }
    // --- 手动实现需要特殊处理的 String setter ---

    public void setPatientId(String patientId) {
        this.patientId = trim(patientId);
    }

    public void setItemClass(String itemClass) {
        this.itemClass = trim(itemClass);
    }

    public void setItemName(String itemName) {
        this.itemName = trim(itemName);
    }

    public void setItemCode(String itemCode) {
        this.itemCode = trim(itemCode);
    }

    public void setItemSpec(String itemSpec) {
        this.itemSpec = trim(itemSpec);
    }

    public void setUnits(String units) {
        this.units = trim(units);
    }

    public void setOrderedBy(String orderedBy) {
        this.orderedBy = trim(orderedBy);
    }

    public void setPerformedBy(String performedBy) {
        this.performedBy = trim(performedBy);
    }

    public void setRcptNo(String rcptNo) {
        this.rcptNo = trim(rcptNo);
    }
}